#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "cpu.h"
#include "interruptmanager.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
class QTextEdit;
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    
    // 公共访问方法
    CPU* getCpu() const;
    QTextEdit* getOutputTextEdit() const;

private slots:
    void on_runButton_clicked();
    void on_stepButton_clicked();
    void on_resetButton_clicked();
    void on_interruptButton_clicked();
    void on_loadExampleButton_clicked();
    void on_saveButton_clicked();
    void on_loadButton_clicked();

private:
    Ui::MainWindow *ui;
    CPU* cpu;
    InterruptManager* interruptManager;
    QStringList instructionList;
    int currentInstructionIndex;
    
    void setupUI();
    void setupInterrupts();
    void updateRegistersDisplay();
    void updateMemoryDisplay();
    void updateCodeDisplay();
    void executeCurrentInstruction();
    void loadExampleCode();
};
#endif // MAINWINDOW_H    